package interfaz;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLayeredPane;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import javax.swing.ImageIcon;
import java.awt.Font;
import javax.swing.JButton;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.awt.Toolkit;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class MenuPrincipal extends JFrame {

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					MenuPrincipal frame = new MenuPrincipal();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public MenuPrincipal() {
		setIconImage(Toolkit.getDefaultToolkit().getImage(MenuPrincipal.class.getResource("/assets/Footxi.png")));
		setResizable(false);
		addComponentListener(new ComponentAdapter() {
			@Override
			public void componentResized(ComponentEvent e) {
				System.out.print("Exito!!");
			}
		});
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 800, 600);
		
		JLayeredPane layeredPane = new JLayeredPane();
		GroupLayout groupLayout = new GroupLayout(getContentPane());
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.TRAILING)
				.addComponent(layeredPane, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 794, Short.MAX_VALUE)
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addComponent(layeredPane, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 562, Short.MAX_VALUE)
		);
		
		JButton button = new JButton("Iniciar Sesion");
		button.setFont(new Font("Tahoma", Font.PLAIN, 15));
		button.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				inicioDeSesion inicio = new inicioDeSesion();
				inicio.setVisible(true);
			}
		});
		
		JLabel lblTitulo = new JLabel("");
		lblTitulo.setIcon(new ImageIcon(MenuPrincipal.class.getResource("/assets/menuPrincipal/FutbolManager.png")));
		lblTitulo.setBounds(180, 6, 427, 220);
		layeredPane.add(lblTitulo);
		button.setBounds(325, 257, 118, 34);
		layeredPane.add(button);
		
		JButton button_1 = new JButton("Registrarse");
		button_1.setFont(new Font("Tahoma", Font.PLAIN, 15));
		button_1.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				
				RegistroDeUsuario registro = new RegistroDeUsuario();
				registro.setVisible(true);
				setVisible(false);
				registro.addWindowListener(new WindowAdapter() {
					@Override
					public void windowClosed(WindowEvent e) {
						// TODO Vuelve a abrir la ventana del menu principal
						super.windowDeactivated(e);
						setVisible(true);
					}
				});
			}
		});
		
		button_1.setBounds(325, 309, 118, 34);
		layeredPane.add(button_1);
		
		JButton button_2 = new JButton("Acerca de");
		button_2.setFont(new Font("Tahoma", Font.PLAIN, 15));
		button_2.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				AcercaDe info = new AcercaDe(new Dimension(800, 600));
				info.setVisible(true);
			}
		});
		button_2.setBounds(325, 361, 118, 34);
		layeredPane.add(button_2);
		
		JButton button_3 = new JButton("Salir");
		button_3.setFont(new Font("Tahoma", Font.PLAIN, 15));
		button_3.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				System.exit(0);
			}
		});
		button_3.setBounds(643, 456, 67, 31);
		layeredPane.add(button_3);
		
		JLabel lblFondo = new JLabel("");
		
		lblFondo.setIcon(new ImageIcon(MenuPrincipal.class.getResource("/assets/menuPrincipal/futbol2.jpg")));
		lblFondo.setBounds(0, 0, 794, 572);
		layeredPane.add(lblFondo);
		getContentPane().setLayout(groupLayout);
	}
}
